package com.cl.master.service.impl;

import com.cl.master.domain.Company;
import com.cl.master.mapper.CompanyMapper;
import com.cl.master.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Author xc
 * @Date 2023/4/26 15:38
 * @Version 1.0
 */
@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    CompanyMapper companyMapper;

    @Override
    public List<Map<String, Object>> getCompanyData() {
        List<Map<String,Object>> data = companyMapper.getCompanyData();
        return data;
    }

    @Override
    public Collection<Company> getAllCompany() {

        /*try {
            //换成你的文件名
            BufferedReader reader = new BufferedReader(
                    new FileReader("C:\\Users\\10160\\Desktop\\大三上作业\\服务外包\\数据\\data.csv"));
            //第一行信息，为标题信息，不用,如果需要，注释掉
            //reader.readLine();
            String line = null;
            HashSet<String> set = new HashSet<>();
            while ((line = reader.readLine()) != null) {
                //CSV格式文件为逗号分隔符文件，这里根据逗号切分
                String item[] = line.split(",");
                String companyCode = item[0];

                if(set.contains(companyCode)) {

                }else {
                    set.add(companyCode);
                    Company company = new Company("xxx",companyCode,true);
                    System.out.println(company);
                    companyMapper.addCompany(company);
                }
                *//**
         * SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
         * String time = "2019-09-19";
         * Date date = ft.parse(time)
         *//*
         *//*企业实例*//*

                //String addCompany = "insert into company (company_name, company_code, company_state) values ('han','"+companyCode+"',1)";
                //jdbcTemplate.update(addCompany);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }*/

        Collection<Company> allCompany = companyMapper.getAllCompany();
        System.out.println("数据处理完成");
        return allCompany;
    }

    @Override
    public Company getCompanyById(Integer id) {
        Company company = companyMapper.getCompanyById(id);
        return company;
    }

    @Override
    public void addCompany(Company company) {
        companyMapper.addCompany(company);
    }

    @Override
    public void delCompany(Integer id) {
        companyMapper.delCompany(id);
    }

    @Override
    public void alter() {
        companyMapper.alter();
    }

    @Override
    public void updateCompany(Company company) {
        companyMapper.updateCompany(company);
    }
}

